package com.example.kotlinmvvm

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.example.kotlinmvvm.BR

abstract class BaseFragment<T : ViewDataBinding, M : BaseViewModel> : Fragment() {

    lateinit var databinding: T
    abstract val viewModel: M
    abstract val layoutId: Int

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        databinding = DataBindingUtil.inflate(inflater, layoutId, container, false)
        databinding.setVariable(BR.vm, viewModel)
        databinding.lifecycleOwner = this
        initView()
        initData()
        return databinding.root
    }


    open fun initView() {
    }

    open fun initData() {
    }

}